package com.zyw.controller.clothing;

import com.zyw.entity.ClothingCategory;
import com.zyw.entity.PersonnelDepartment;
import com.zyw.enums.ManagermentSystemEnum;
import com.zyw.from.ClothingFrom;
import com.zyw.from.personnelFrom;
import com.zyw.service.clothing.ClothingCategoryService;
import com.zyw.util.ResultVOUtil;
import com.zyw.vo.LayUITableVO;
import com.zyw.vo.ResultVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;


@Controller
@Slf4j
@RequestMapping("/clothing/category")
public class ClothingCategoryController {



    @Autowired
    public ClothingCategoryService clothingCategoryService;

    //查询二三级分类目录
    @GetMapping("/sexType")
    @ResponseBody
    public ResultVO levelTwo(Integer sexType){
        if (sexType==null){
            log.info("【查询分级目录】 接收参数有误！ parentId={}",sexType);
            return ResultVOUtil.error(ManagermentSystemEnum.PARAM_ERROR);
        }
        //查询全部二级目录
        List<ClothingCategory> appCategoryVOList = clothingCategoryService.findBySex(sexType);

        return ResultVOUtil.ok(appCategoryVOList);
    }

    //菜品类别展示
    @GetMapping("/index")
    public String index(){


        return "clothing/category/index";

    }
    //获取菜品类别信息
    @GetMapping("/list")
    @ResponseBody
    public LayUITableVO<List<ClothingCategory>> list (@RequestParam(defaultValue = "1") Integer page,
                                                         @RequestParam(defaultValue = "10") Integer limit,
                                                      ClothingFrom from){

        Map<String ,Object> map = new HashMap<>();
        map.put("page",page);
        map.put("limit",limit);
        map.put("from",from);
        LayUITableVO< List<ClothingCategory>> vo = clothingCategoryService.findPage(map);


        return vo;
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/edit-ui")
    public String editUI(String id, Model model){

       ClothingCategory clothingCategory = clothingCategoryService.selectById(id);



        model.addAttribute("clothingCategory",clothingCategory);

        return "clothing/category/edit";

    }

    //执行修改
    @PostMapping("/edit")
    @ResponseBody
    public ResultVO edit(ClothingCategory clothingCategory){

        clothingCategoryService.update(clothingCategory);

        return ResultVOUtil.ok();
    }

    //修改菜品类别信息1（查询指定id菜品分类详情）
    @GetMapping("/add-ui")
    public String addUI(){

        return "clothing/category/add";

    }
    //执行修改
    @PostMapping("/add")
    @ResponseBody
    public ResultVO add(ClothingCategory clothingCategory){

        clothingCategoryService.save(clothingCategory);

        return ResultVOUtil.ok();
    }

    //执行删除
    @PostMapping("/del")
    @ResponseBody
    public ResultVO del(String id){
        clothingCategoryService.delelteById(id);
        return ResultVOUtil.ok();
    }


}
